﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace IPC.Communication.Core.Address
{
    public class FujiCommandSettingTypeAddress : DeviceAddressDataBase
    {
        public byte DataCode
        {
            get;
            set;
        }

        public string AddressHeader
        {
            get;
            set;
        }

        public override void Parse(string address, ushort length)
        {
            base.Parse(address, length);
        }

        public override string ToString()
        {
            return this.AddressHeader + base.AddressStart.ToString();
        }

        public static OperateResult<FujiCommandSettingTypeAddress> ParseFrom(string address, ushort length)
        {
            OperateResult<FujiCommandSettingTypeAddress> result;
            try
            {
                FujiCommandSettingTypeAddress fujiCommandSettingTypeAddress = new FujiCommandSettingTypeAddress();
                string text = string.Empty;
                string value = string.Empty;
                bool flag = address.IndexOf('.') < 0;
                if (flag)
                {
                    Match match = Regex.Match(address, "^[A-F]+[^0-9]");
                    bool flag2 = !match.Success;
                    if (flag2)
                    {
                        result = new OperateResult<FujiCommandSettingTypeAddress>(StringResources.Language.NotSupportedDataType);
                        return result;
                    }
                    text = match.Value;
                    value = address.Substring(text.Length);
                }
                else
                {
                    string[] array = address.Split(new char[]
					{
						'.'
					}, StringSplitOptions.RemoveEmptyEntries);
                    bool flag3 = array[0][0] != 'W';
                    if (flag3)
                    {
                        result = new OperateResult<FujiCommandSettingTypeAddress>(StringResources.Language.NotSupportedDataType);
                        return result;
                    }
                    text = array[0] + ".";
                    value = array[1];
                }
                fujiCommandSettingTypeAddress.AddressHeader = text;
                fujiCommandSettingTypeAddress.AddressStart = Convert.ToInt32(value);
                fujiCommandSettingTypeAddress.Length = length;
                bool flag4 = text == "TS";
                if (flag4)
                {
                    fujiCommandSettingTypeAddress.DataCode = 10;
                }
                else
                {
                    bool flag5 = text == "TR";
                    if (flag5)
                    {
                        fujiCommandSettingTypeAddress.DataCode = 11;
                    }
                    else
                    {
                        bool flag6 = text == "CS";
                        if (flag6)
                        {
                            fujiCommandSettingTypeAddress.DataCode = 12;
                        }
                        else
                        {
                            bool flag7 = text == "CR";
                            if (flag7)
                            {
                                fujiCommandSettingTypeAddress.DataCode = 13;
                            }
                            else
                            {
                                bool flag8 = text == "BD";
                                if (flag8)
                                {
                                    fujiCommandSettingTypeAddress.DataCode = 14;
                                }
                                else
                                {
                                    bool flag9 = text == "WL";
                                    if (flag9)
                                    {
                                        fujiCommandSettingTypeAddress.DataCode = 20;
                                    }
                                    else
                                    {
                                        bool flag10 = text == "B";
                                        if (flag10)
                                        {
                                            fujiCommandSettingTypeAddress.DataCode = 0;
                                        }
                                        else
                                        {
                                            bool flag11 = text == "M";
                                            if (flag11)
                                            {
                                                fujiCommandSettingTypeAddress.DataCode = 1;
                                            }
                                            else
                                            {
                                                bool flag12 = text == "K";
                                                if (flag12)
                                                {
                                                    fujiCommandSettingTypeAddress.DataCode = 2;
                                                }
                                                else
                                                {
                                                    bool flag13 = text == "F";
                                                    if (flag13)
                                                    {
                                                        fujiCommandSettingTypeAddress.DataCode = 3;
                                                    }
                                                    else
                                                    {
                                                        bool flag14 = text == "A";
                                                        if (flag14)
                                                        {
                                                            fujiCommandSettingTypeAddress.DataCode = 4;
                                                        }
                                                        else
                                                        {
                                                            bool flag15 = text == "D";
                                                            if (flag15)
                                                            {
                                                                fujiCommandSettingTypeAddress.DataCode = 5;
                                                            }
                                                            else
                                                            {
                                                                bool flag16 = text == "S";
                                                                if (flag16)
                                                                {
                                                                    fujiCommandSettingTypeAddress.DataCode = 8;
                                                                }
                                                                else
                                                                {
                                                                    bool flag17 = text.StartsWith("W");
                                                                    if (flag17)
                                                                    {
                                                                        int num = Convert.ToInt32(text.Substring(1));
                                                                        bool flag18 = num == 9;
                                                                        if (flag18)
                                                                        {
                                                                            fujiCommandSettingTypeAddress.DataCode = 9;
                                                                        }
                                                                        else
                                                                        {
                                                                            bool flag19 = num >= 21 && num <= 26;
                                                                            if (flag19)
                                                                            {
                                                                                fujiCommandSettingTypeAddress.DataCode = (byte)num;
                                                                            }
                                                                            else
                                                                            {
                                                                                bool flag20 = num >= 30 && num <= 109;
                                                                                if (flag20)
                                                                                {
                                                                                    fujiCommandSettingTypeAddress.DataCode = (byte)num;
                                                                                }
                                                                                else
                                                                                {
                                                                                    bool flag21 = num >= 120 && num <= 123;
                                                                                    if (flag21)
                                                                                    {
                                                                                        fujiCommandSettingTypeAddress.DataCode = (byte)num;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        bool flag22 = num == 125;
                                                                                        if (!flag22)
                                                                                        {
                                                                                            result = new OperateResult<FujiCommandSettingTypeAddress>(StringResources.Language.NotSupportedDataType);
                                                                                            return result;
                                                                                        }
                                                                                        fujiCommandSettingTypeAddress.DataCode = (byte)num;
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                result = OperateResult.CreateSuccessResult<FujiCommandSettingTypeAddress>(fujiCommandSettingTypeAddress);
            }
            catch (Exception ex)
            {
                result = new OperateResult<FujiCommandSettingTypeAddress>(ex.Message);
            }
            return result;
        }
    }
}
